<template>
    <div>
        <h1>登录中心</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">账号</td>
                    <td><input type="text" v-model="queryInfo.username"/></td>
                </tr>
                <tr>
                    <td align="right">密码</td>
                    <td>
                        <input type="password" v-model="queryInfo.userpwd">
                    </td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td>
                        <input type="button" value="登录" class="btn btn-primary" @click="login">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">

import {ref,reactive} from 'vue'
import axios  from 'axios';
import {useRouter} from 'vue-router';
import router from '@/router';
import {useUserStore} from '../stores/user'

const UserStore=useUserStore()
let queryInfo=reactive({
    username:'',
    userpwd:'',
})

const login=()=>{
    //1.判断有效性
    if(queryInfo.username==""){
        alert("账号不能为空");
        return;
    }
    if(queryInfo.userpwd==""){
        alert("密码不能为空");
        return;
    }
    //2.发送网络请求去后端验证账号和密码在数据库中是否存在
    axios({
        method:'get',
        url:'/api/Admin/AdminLogin',
        params:queryInfo,
    })
    .then(res=>{
        console.log(res);
        if(res.data==-1){
            alert("用户名不正确");
            return;
        }
        if(res.data==-2){
            alert("密码不正确");
            return;
        }
        alert("登录成功");
        UserStore.userInfo=res.data;
        router.push('/memberlist');
    })
    .catch(err=>{
        console.log(err);
    })



}






</script>

<style scoped>

</style>